[PATCH md 000 of 5] Introduction

Following are 5 patches that start by adding sysfs support to 'md',
and then proceed to add functionality that makes use if it.

For example:
The raid5 stripe cache can be resized with
echo NNN > /sys/block/mdX/md/raid5/stripe_cache_size
An array can resync'ed with
echo repair > /sys/block/mdX/md/scan_mode

On raid5, the number of parity mismatches found will be reported in
/sys/block/mdX/md/mismatch_cnd

You will note that raid5 has got the most new functionality. Matching
functionality for other md personalities will follow.

These patches should be suitable for merging after 2.6.14 is released.

NeilBrown


[PATCH md 001 of 5] Initial sysfs support for md
[PATCH md 002 of 5] Extend md sysfs support to component devices.
[PATCH md 003 of 5] Add kobject/sysfs support to raid5
[PATCH md 004 of 5] Allow a manual resync with md
[PATCH md 005 of 5] Teach raid5 the difference between 'check' and 'repair'.
-
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
NeilBrown [ Di, 04 Oktober 2005 07:23 ] [ ID #995589 ]

[PATCH md 001 of 5] Initial sysfs support for md

Start using kobjects in mddevs, and provide a couple
of simple attributes (level and disks).
Attributes live in
/sys/block/mdX/md/attr-name


Signed-off-by: Neil Brown <neilb [at] suse.de>

### Diffstat output
./drivers/md/md.c | 86 +++++++++++++++++++++++++++++++++++++++++++-
./include/linux/raid/md_k.h | 2 +
2 files changed, 87 insertions(+), 1 deletion(-)

diff ./drivers/md/md.c~current~ ./drivers/md/md.c
--- ./drivers/md/md.c~current~ 2005-10-04 11:54:43.000000000 +1000
+++ ./drivers/md/md.c 2005-10-04 12:16:53.000000000 +1000
[at] [at] -181,7 +181,7 [at] [at] static void mddev_put(mddev_t *mddev)
if (!mddev->raid_disks && list_empty(&mddev->disks)) {
list_del(&mddev->all_mddevs);
blk_put_queue(mddev->queue);
- kfree(mddev);
+ kobject_unregister(&mddev->kobj);
}
spin_unlock(&all_mddevs_lock);
}
[at] [at] -1551,6 +1551,85 [at] [at] static void analyze_sbs(mddev_t * mddev)

}

+struct md_sysfs_entry {
+ struct attribute attr;
+ ssize_t (*show)(mddev_t *, char *);
+ ssize_t (*store)(mddev_t *, const char *, size_t);
+};
+
+static ssize_t
+md_show_level(mddev_t *mddev, char *page)
+{
+ mdk_personality_t *p = mddev->pers;
+ if (p == NULL)
+ return 0;
+ if (mddev->level >= 0)
+ return sprintf(page, "RAID-%d\n", mddev->level);
+ else
+ return sprintf(page, "%s\n", p->name);
+}
+
+static struct md_sysfs_entry md_level = {
+ .attr = {.name = "level", .mode = S_IRUGO },
+ .show = md_show_level,
+};
+
+static ssize_t
+md_show_rdisks(mddev_t *mddev, char *page)
+{
+ return sprintf(page, "%d\n", mddev->raid_disks);
+}
+
+static struct md_sysfs_entry md_raid_disks = {
+ .attr = {.name = "raid_disks", .mode = S_IRUGO },
+ .show = md_show_rdisks,
+};
+
+static struct attribute *md_default_attrs[] = {
+ &md_level.attr,
+ &md_raid_disks.attr,
+ NULL,
+};
+
+static ssize_t
+md_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
+{
+ struct md_sysfs_entry *entry = container_of(attr, struct md_sysfs_entry, attr);
+ mddev_t *mddev = container_of(kobj, struct mddev_s, kobj);
+
+ if (!entry->show)
+ return -EIO;
+ return entry->show(mddev, page);
+}
+
+static ssize_t
+md_attr_store(struct kobject *kobj, struct attribute *attr,
+ const char *page, size_t length)
+{
+ struct md_sysfs_entry *entry = container_of(attr, struct md_sysfs_entry, attr);
+ mddev_t *mddev = container_of(kobj, struct mddev_s, kobj);
+
+ if (!entry->store)
+ return -EIO;
+ return entry->store(mddev, page, length);
+}
+
+static void md_free(struct kobject *ko)
+{
+ mddev_t *mddev = container_of(ko, mddev_t, kobj);
+ kfree(mddev);
+}
+
+static struct sysfs_ops md_sysfs_ops = {
+ .show = md_attr_show,
+ .store = md_attr_store,
+};
+static struct kobj_type md_ktype = {
+ .release = md_free,
+ .sysfs_ops = &md_sysfs_ops,
+ .default_attrs = md_default_attrs,
+};
+
int mdp_major = 0;

static struct kobject *md_probe(dev_t dev, int *part, void *data)
[at] [at] -1592,6 +1671,11 [at] [at] static struct kobject *md_probe(dev_t de
add_disk(disk);
mddev->gendisk = disk;
up(&disks_sem);
+ mddev->kobj.parent = kobject_get(&disk->kobj);
+ mddev->kobj.k_name = NULL;
+ snprintf(mddev->kobj.name, KOBJ_NAME_LEN, "%s", "md");
+ mddev->kobj.ktype = &md_ktype;
+ kobject_register(&mddev->kobj);
return NULL;
}


diff ./include/linux/raid/md_k.h~current~ ./include/linux/raid/md_k.h
--- ./include/linux/raid/md_k.h~current~ 2005-10-04 11:54:43.000000000 +1000
+++ ./include/linux/raid/md_k.h 2005-10-04 11:54:43.000000000 +1000
[at] [at] -148,6 +148,8 [at] [at] struct mddev_s

struct gendisk *gendisk;

+ struct kobject kobj;
+
/* Superblock information */
int major_version,
minor_version,
-
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
NeilBrown [ Di, 04 Oktober 2005 07:23 ] [ ID #995590 ]

Re: [PATCH md 002 of 5] Extend md sysfs support to componentdevices.

NeilBrown <neilb [at] suse.de> wrote:
>
> + if (rdev2->raid_disk >= 0) {
> + char nm[20];

fyi, the two instances of nm[] in this function will consume 40 bytes of
stack (gcc is lame). If you were to put a single nm[20] at the outermost
level of the function and then use it in both places, only 20 bytes of
stack would be used.
-
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Andrew Morton [ Mi, 12 Oktober 2005 01:51 ] [ ID #1007272 ]

Re: [PATCH md 003 of 5] Add kobject/sysfs support to raid5

NeilBrown <neilb [at] suse.de> wrote:
>
> +static ssize_t
> +raid5_store_stripe_cache_size(raid5_conf_t *conf, const char *page, ssize_t len)
> +{
> + char *end;
> + int new;
> + if (len >= PAGE_SIZE)
> + return -EINVAL;

Can `len' be negative?
-
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Andrew Morton [ Mi, 12 Oktober 2005 01:54 ] [ ID #1007273 ]

Re: [PATCH md 004 of 5] Allow a manual resync with md

NeilBrown <neilb [at] suse.de> wrote:
>
> static ssize_t
> +md_show_scan(mddev_t *mddev, char *page)
> +{
> + char *type = "none";
> + if (mddev->recovery &
> + ((1<<MD_RECOVERY_RUNNING) || (1<<MD_RECOVERY_NEEDED))) {

Shouldn't this be a bitwise OR?

> + if (mddev->recovery & (1<<MD_RECOVERY_SYNC)) {
> + if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
> + type = "resync";
> + else if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery))
> + type = "check";
> + else
> + type = "repair";
> + } else
> + type = "recover";
> + }
> + return sprintf(page, "%s\n", type);
> +}
> +
> +static ssize_t
> +md_store_scan(mddev_t *mddev, const char *page, size_t len)
> +{
> + int canscan=0;
> + if (mddev->recovery &
> + ((1<<MD_RECOVERY_RUNNING) || (1<<MD_RECOVERY_NEEDED)))

And this?

> + return -EBUSY;
-
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Andrew Morton [ Mi, 12 Oktober 2005 01:56 ] [ ID #1007274 ]

Re: [PATCH md 004 of 5] Allow a manual resync with md

NeilBrown <neilb [at] suse.de> wrote:
>
> static ssize_t
> +md_show_scan(mddev_t *mddev, char *page)
> +{
> + char *type = "none";
> + if (mddev->recovery &
> + ((1<<MD_RECOVERY_RUNNING) || (1<<MD_RECOVERY_NEEDED))) {
> + if (mddev->recovery & (1<<MD_RECOVERY_SYNC)) {
> + if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
> + type = "resync";
> + else if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery))
> + type = "check";
> + else
> + type = "repair";
> + } else
> + type = "recover";
> + }
> + return sprintf(page, "%s\n", type);
> +}
> +
> +static ssize_t
> +md_store_scan(mddev_t *mddev, const char *page, size_t len)
> +{
> + int canscan=0;
> + if (mddev->recovery &
> + ((1<<MD_RECOVERY_RUNNING) || (1<<MD_RECOVERY_NEEDED)))
> + return -EBUSY;

I'd be inclined to just use test_bit() here - it's pretty cheap.
-
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Andrew Morton [ Mi, 12 Oktober 2005 01:57 ] [ ID #1007275 ]

Re: [PATCH md 004 of 5] Allow a manual resync with md

On Tuesday October 11, akpm [at] osdl.org wrote:
> NeilBrown <neilb [at] suse.de> wrote:
> >
> > static ssize_t
> > +md_show_scan(mddev_t *mddev, char *page)
> > +{
> > + char *type = "none";
> > + if (mddev->recovery &
> > + ((1<<MD_RECOVERY_RUNNING) || (1<<MD_RECOVERY_NEEDED))) {
>
> Shouldn't this be a bitwise OR?

Yes, though given that my testing showed it worked fine, there is
little practical difference!!

The constant value is becomes '1' instead of '33', and the '32' bit is
only set for extremely short periods of time, so not testing doesn't
make a visible difference!

I will, ofcourse, fix it.

Thanks for reviewing the patches.

NeilBrown

-
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
NeilBrown [ Do, 13 Oktober 2005 07:18 ] [ ID #1008974 ]

Re: [PATCH md 003 of 5] Add kobject/sysfs support to raid5

On Tuesday October 11, akpm [at] osdl.org wrote:
> NeilBrown <neilb [at] suse.de> wrote:
> >
> > +static ssize_t
> > +raid5_store_stripe_cache_size(raid5_conf_t *conf, const char *page, ssize_t len)
> > +{
> > + char *end;
> > + int new;
> > + if (len >= PAGE_SIZE)
> > + return -EINVAL;
>
> Can `len' be negative?

No, because sysfs_write_file only calls flush_write_buffer
with a 'len' that is >0, and this is the only path that leads to
raid5_store_stripe_cache_size.
Do you think I should be defensive and double-check in
raid5_attr_store?

NeilBrown
-
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
NeilBrown [ Do, 13 Oktober 2005 07:24 ] [ ID #1008975 ]
Linux » gmane.linux.raid » [PATCH md 000 of 5] Introduction

Vorheriges Thema: RAID
Nächstes Thema: Recovery raid5 after sata cable failure.